# Zope imports
from AccessControl import ClassSecurityInfo

# zope imports
from zope.interface import implements

# Archetypes imports
from Products.Archetypes.atapi import *
from Products.ATContentTypes.content.image import ATImage

# ATReferenceBrowserWidget imports
from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget

# iqpp.plone.simpleimagemapping imports
from iqpp.plone.simpleimagemapping.config import PROJECTNAME
from iqpp.plone.simpleimagemapping.interfaces import IMappedImage

schema = Schema((
    ReferenceField(
        name='relatedObject',
        multiValued=True,
        relationship='simpleimagemapping',
        widget=ReferenceBrowserWidget(
            label="Related Object",
            label_msgid="schema_related_object_label",
            description='Please select an object to which this image is related',
            description_msgid="schema_related_object_description",
            i18n_domain='iqpp.plone.simpleimagemapping',
            show_path=1,        
            allow_search=1, 
            allow_browse=1,
            startup_directory="/",
            available_indexes={'Title'         : "Product's Title",
                               'SearchableText':'Free text search',
                               'Description'   : "Object's description"},
            ),    
    ),

    IntegerField(
        name='position',
        required="1",
        default="1",
        widget=IntegerWidget(
            label="Position",
            label_msgid="schema_position_label",
            description = "The order position of the image",
            description_msgid = "schema_position_description",
            i18n_domain="iqpp.plone.simpleimagemapping",
        ),
),    
),
)

schema = ATImage.schema.copy() + schema

class MappedImage(ATImage):
    """
    """
    implements(IMappedImage)
    security = ClassSecurityInfo()
    _at_rename_after_creation = True
    schema = schema
        
registerType(MappedImage, PROJECTNAME)